package qsoft.omanga.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.List;

import qsoft.omanga.business.entities.Manga;
import qsoft.omanga.ui.custom.ListMangaHolder;
import qsoft.omanga.ui.custom.RankingMangaHolder;

/**
 * 
 * @author sontt
 * 
 */
public class MangaAdapter extends BaseAdapter {
    /**
     * 
     */
    private Context context;
    /**
     * 
     */
    private List<Manga> items;
    /**
     * 
     */
    private boolean optionList;

    /**
     * 
     * @param context
     *            Context
     * @param listMangas
     *            List<Manga>
     * @param optionList
     *            boolean
     */
    public MangaAdapter(Context context, List<Manga> listMangas,
            boolean optionList) {
        this.context = context;
        this.items = listMangas;
        this.optionList = optionList;
    }

    @Override
    public int getCount() {
        return items.size();
    }

    @Override
    public Object getItem(int position) {
        return items.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view;
        if (optionList) {
            RankingMangaHolder rowView = new RankingMangaHolder(context,
                    items.get(position));
            view = rowView.getRow(convertView);
        } else {
            ListMangaHolder rowView = new ListMangaHolder(context,
                    items.get(position));
            view = rowView.getRow(convertView);
        }
        return view;
    }
}
